package com.newbsd.web.maventest.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.newbsd.web.maventest.dao.UserDao;
import com.newbsd.web.maventest.dao.impl.UserDaoImpl;
import com.newbsd.web.maventest.pojo.User;


/**
 * Servlet implementation class UserQueryServlet
 */
@WebServlet("/UserQueryServlet")
public class UserQueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private UserDao userDao = new UserDaoImpl();

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取数据库中user表的信息,丢到request中,从而在页面中获取到用户列表
		//int id = Integer.parseInt(request.getParameter("id"));
		String username = request.getParameter("username");
		User user = userDao.getUser(username);

		request.setAttribute("user", user);
		request.getRequestDispatcher("/userinfo.jsp").forward(request,
				response);
		
	}

}
